<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button class="btn">注册用户</button>
    <script src="./axios.js"></script>

    <script>
        document.querySelector('.btn').addEventListener('click', function () {
            // 通过axios提交用户数据，完成用户注册
            axios({
                url: 'https://hmajax.itheima.net/api/register',
                method: 'POST',
                data: {
                    username: 'gg1234567',
                    password: '123456'
                }
            })
                .then(res => {
                    console.log(res.data)
                    alert('注册成功')
                })
                .catch(err => {
                    alert(err.response.data.message)  // 提示账号已被注册
                })
        })

    </script>
</body>

</html>